import editor from 'wangeditor'

class EditorWangManagment{
    init(editorDomId = '#editor'){
        $('.answer-textarea-div').addClass('disnone')
        $('.compilediv-bottom-menu').addClass('disnone')
        $('#compilediv').addClass('disnone')
        this.editor = new editor(editorDomId)
        this.editor.create()
        this.setImgIcon() // 处理编辑器图片按钮
        this.editContainer = $('.w-e-text')
    }

    setImgIcon(){
        const that = this
        if($('.w-e-toolbar').length > 0){
            $('.w-e-toolbar').ready(() => {
                const iconDom = $('.w-e-menu')
                for(let i = 0; i < iconDom.length; i++){
                    if(iconDom.eq(i).children('i').hasClass('w-e-icon-image')){
                        iconDom.eq(i).remove()
                        break
                    }
                }
                $('.w-e-toolbar').append(`<div class="w-e-menu" id="upload-img-icon" style="z-index:10001;"><i class="w-e-icon-image"></i></div>`)
            })
        }else{
            setTimeout(() => {
                that.setImgIcon()
            }, 10)
        }
    }
}

export { EditorWangManagment }